<?php

use backend\widgets\Bar;
use backend\grid\CheckboxColumn;
use backend\grid\ActionColumn;
use backend\grid\GridView;
use yii\widgets\Pjax;
use yii\helpers\Html;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\GoodsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title                   = '商品管理';
$this->params['breadcrumbs'][] = [
    'label' => "分类",
    'url'   => \yii\helpers\Url::to(['good-type/index'])
];
$this->params['breadcrumbs'][] = "商品";
?>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <?= $this->render('/widgets/_ibox-title') ?>
            <div class="ibox-content">
                <?= Bar::widget([
                    'item_type' => $searchModel->type,
                    'template'  => "{refresh}{createchild}{delete}"
                ]) ?>
                <!--                --><? //= $this->render('_search', ['model' => $searchModel]); ?>
                <?php Pjax::begin(); ?>
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel'  => $searchModel,
                    'columns'      => [
                        ['class' => CheckboxColumn::className()],

                        [
                            'attribute' => 'id',
                            'width'     => '10px',
                        ],
//                        'type',
//                        'img',
//                        'right',
                        'title',
                        // 'description',
                        // 'color',
                        [
                            'attribute' => 'price',
                            'value'     => function ($model) {
                                return '¥' . number_format($model->price / 100, 2);
                            }
                        ],
                        [
                            'attribute' => 'availability_period',
                            'value'     => function ($model) {
                                return $model->availability_period . " 月";
                            }

                        ],
                        [
                            'attribute' => 'availability_num',
                            'value'     => function ($model) {
                                return $model->availability_num . " 次";
                            }

                        ],
                        'created_at:datetime',
                        'updated_at:datetime',


                        [
                            'class' => ActionColumn::className(),
                            'width' => '150px',
                        ]
                    ],
                ]); ?>
                <?php Pjax::end(); ?>
            </div>
        </div>
    </div>
</div>
